package game.adm.controller;
import game.adm.dao.dto.ConfigDTO;
import game.adm.entity.ConfigEntityManager;
import game.adm.struts.form.ConfigForm;
import game.web.base.Constants;
import projectx.core.base.ProjectXSystemException;
import projectx.core.base.ProjectXUserException;
import projectx.transaction.TransactionHandler;
import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXDbTrxController;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;

public class ConfigSaveController extends ProjectXDbTrxController {

	protected ConfigSaveController(UserContext uc, ProjectXForm form) {
		super(uc, form);
	}

	@Override
	public Object execute() throws ProjectXUserException,
			ProjectXSystemException {
		debugBegin();
		UserContext uc = getUc();
		String ip = (String) uc.get(ConstantsProjectX.CURRENT_IP);
		ConfigForm form = (ConfigForm) getForm();
		ConfigDTO dto = new ConfigDTO();
		dto.setCofigid(form.getCofigid());
		dto.setHelplink(form.getHelplink());
		dto.setUserscale(form.getUserscale()/100);
		dto.setWebsitename(form.getWebsitename());
		dto.setCreatetime(getCurrentTimeString());
		dto.setUpdatetime(getCurrentTimeString());
		dto.setCreateip(ip);
		dto.setUpdateip(ip);
		boolean flag= ConfigEntityManager.insert(dto);
		uc.put(Constants.ADM_CONFIG_FLAG, flag+"");
		debugEnd();
		return null;
	}

	public static Object execute(UserContext uc, ProjectXForm form)
			throws ProjectXUserException, ProjectXSystemException {
		return TransactionHandler.call(new ConfigSaveController(uc, form));
	}
}
